package com.example.framework.service.impl;

import com.example.framework.myBatisGenerator.mapper.UmsAdminMapper;
import com.example.framework.myBatisGenerator.model.UmsAdmin;
import com.example.framework.myBatisGenerator.model.UmsAdminExample;
import com.example.framework.service.UmsAdminService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UmsAdminServiceImpl implements UmsAdminService {
    //src/main/resources/com/example/framework/myBatisGenerator/mapper/UmsAdminMapper.xml
    @Autowired
    private UmsAdminMapper adminMapper;

    @Override
    public UmsAdmin register(UmsAdmin umsAdminParam) {
        UmsAdmin umsAdmin = new UmsAdmin();
        BeanUtils.copyProperties(umsAdminParam, umsAdmin);
        //用户名占用
        UmsAdminExample example = new UmsAdminExample();
        example.createCriteria().andUsernameEqualTo(umsAdmin.getUsername());
        List<UmsAdmin> umsAdminList = adminMapper.selectByExample(example);
        if (umsAdminList.size() > 0) {
            return null;
        }
        //密码 TODO 加密处理
        umsAdmin.setPassword(umsAdmin.getPassword());
        //创建时间
        umsAdmin.setCreateTime(new Date());
        //帐号启用状态：1->启用
        umsAdmin.setStatus(1);
        // insert
        adminMapper.insert(umsAdmin);
        return umsAdmin;
    }

    @Override
    public String login(String username, String password) {
        // TODO
        return null;
    }
}
